package com.bright.ghj.overt.converter;

import com.bright.ghj.common.converter.BaseConverter;
import com.bright.ghj.overt.pojo.command.CommonCommand;
import com.bright.ghj.overt.pojo.dto.AsyncMessageDTO;
import com.bright.ghj.overt.pojo.po.primary.AsyncMessage;
import com.bright.ghj.overt.pojo.vo.AsyncMessageVO;
import org.mapstruct.Mapper;

import java.util.ArrayList;
import java.util.List;

import static com.bright.ghj.overt.enums.AsyncTaskExecInfo.getCategoryFromStatus;

/**
 * @author Tz
 * @date 2024/01/22 15:03
 * @Description 异步任务消息实体的 转换器
 */
@Mapper(componentModel = "spring")
public interface AsyncMessageConverter extends BaseConverter<AsyncMessage, AsyncMessageDTO, AsyncMessageVO, CommonCommand> {


    /**
     * 自定义List-PO 转 List-DTO 处理状态分类的字段
     * @param poList
     * @return
     */
    @Override
    default List<AsyncMessageDTO> poConvertDTO(List<AsyncMessage> poList) {
        if ( poList == null ) {
            return null;
        }

        List<AsyncMessageDTO> list = new ArrayList<AsyncMessageDTO>( poList.size() );
        for ( AsyncMessage asyncMessage : poList ) {
            asyncMessage.setStatusCategory(getCategoryFromStatus(asyncMessage.getExecStatus()));
            list.add( poConvertDTO( asyncMessage ) );
        }

        return list;
    }

}
